package org.cangkuguanli.zhuyaohui.controller;


import org.cangkuguanli.zhuyaohui.bean.ShoppingCart;
import org.cangkuguanli.zhuyaohui.mapper.ShoppingCartMapper;
import org.cangkuguanli.zhuyaohui.util.JsonResult;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
@CrossOrigin("*")
@RequestMapping("/shopping_cart")
@RestController
public class ShoppingCartController {
    @Resource
    private ShoppingCartMapper shoppingCartMapper;
    @RequestMapping("/find")
    public JsonResult findByUserId(String userId) {

        List<ShoppingCart> list = shoppingCartMapper.findByUserId(userId);

        JsonResult result = new JsonResult(true,200,list,"");

        return result;
    }
    @RequestMapping("/add")
    public JsonResult addCart(ShoppingCart sc) {
        ShoppingCartMapper.add(sc);
        JsonResult result = new JsonResult(true,200,"success","");
        return result;
    }
    @RequestMapping("/update")
    public JsonResult updateCart(ShoppingCart sc) {
        ShoppingCartMapper.update(sc);
        JsonResult result = new JsonResult(true,200,"success","");
        return result;
    }
    @RequestMapping("/remove1")
    public JsonResult remove1(ShoppingCart sc) {
        shoppingCartMapper.remove1(sc);
        JsonResult result = new JsonResult(true,200,"success","");
        return result;
    }

    @RequestMapping("/remove1")
    public JsonResult remove2(ShoppingCart sc) {
        shoppingCartMapper.remove2(sc);
        JsonResult result = new JsonResult(true, 200, "success", "");
        return result;
    }
}
